
// 这里我们引入假数据
var postsData = require("../../data/posts-data")

Page({
  data:{
    isClick:true,
    isTwoClick:true,
    isThreeClick:true
  },
  onLoad:function(options){
    var post_content = postsData.postList
    this.setData({
      postlist:post_content
    })    
  },
  onReady:function(){},
  onShow:function(){},
  onHide:function(){},
  onUnload:function(){},
  onPostTap:function(event){
    var postId = event.currentTarget.dataset.postId;
    wx.navigateTo({
      url: 'post-detail/post-detail?id=' + postId ,
      success: function(res){},
      fail: function() {},
      complete: function() {}
    })
  },
  // 这里是采用每一个 item 一个事件的方式
  // onSwiperItemTap:function(event){
  //   var postId = event.currentTarget.dataset.postId;
  //   wx.navigateTo({
  //     url: 'post-detail/post-detail?id=' + postId ,
  //     success: function(res){},
  //     fail: function() {},
  //     complete: function() {}
  //   })
  // }

  onSwiperTap:function(event){
    var postId = event.target.dataset.postId;
    // target 和 currentTarget 的不同
    /**
     * target 指的是当前点击的组件
     * currentTarget 指的是事件捕获的组件
     * 
     * target 指的是 image
     * currentTarget 指的是 Swiper
     * 
     */
    console.log(postId)
    wx.navigateTo({
      url: 'post-detail/post-detail?id=' + postId ,
      success: function(res){},
      fail: function() {},
      complete: function() {}
    })
  },
  onFirstTap:function(event){
    var isClick = this.data.isClick;
    var isTwoClick = this.data.isTwoClick;
    var isThreeClick = this.data.isThreeClick;
    if(isClick){ //这里
      this.setData({
        isTwoClick:true,
        isThreeClick:true
      })
    }
    this.setData({
      isClick:!isClick
    })

    
  },
  onTwoTap:function(event){
    var clickId = event.currentTarget.dataset.postId
    // console.log(clickId)    
    var isClick = this.data.isClick;
    var isTwoClick = this.data.isTwoClick;
    var isThreeClick = this.data.isThreeClick;
    if(isTwoClick){
      this.setData({
        isClick:true,
        isThreeClick:true
      })
    }
    this.setData({
      isTwoClick:!isTwoClick
    })
  },
  onThreeTap:function(event){
    var clickId = event.currentTarget.dataset.postId
    // console.log(clickId)      
    var isClick = this.data.isClick;
    var isTwoClick = this.data.isTwoClick;
    var isThreeClick = this.data.isThreeClick;
    if(isThreeClick){
      this.setData({
        isTwoClick:true,
        isClick:true
      })
    }
    this.setData({
      isThreeClick:!isThreeClick
    })
  },
})